package com.rentplant.controller;

import com.alibaba.fastjson.JSONObject;
import com.rentplant.Pojo.afterservice;
import com.rentplant.Pojo.serviceandorderanditem;
import com.rentplant.service.impl.afterServiceImp;
import com.rentplant.service.impl.orderServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController//让它知道这是controller
@RequestMapping("/afterService")
public class afterServiceController {

    @Autowired
    private afterServiceImp afterserviceimp;

    //查找用户售后服务订单
    @RequestMapping("/AfterService")
    public List<serviceandorderanditem> afterService(@RequestBody JSONObject req){
        try {
            return afterserviceimp.afterService(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }

    }

    //提交售后申请
    @RequestMapping("/addAfterService")
    public boolean addAfterService(@RequestBody JSONObject req){
        try {
            return afterserviceimp.addAfterService(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }


    //查询该订单是否有售后申请
    @RequestMapping("/selectAfterService")
    public  List<afterservice> selectAfterService(@RequestBody JSONObject req){
        try {
            return afterserviceimp.selectAfterService(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }







    //    申请管理
//    查询全部申请并分页
    @RequestMapping("/allApply")
    public List<afterservice> allApply(@RequestBody JSONObject req){
        try {
            return afterserviceimp.allApply(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //    查询全部申请
    @RequestMapping("/allApplys")
    public List<afterservice> allApplys(){
        try {
            return afterserviceimp.allApplys();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //    不同意售后申请
    @RequestMapping("/refuseApply")
    public boolean refuseApply(@RequestBody JSONObject req){
        try {
            return afterserviceimp.refuseApply(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //    按条件查找
    @RequestMapping("/searchAfter")
    public List<afterservice> searchAfter(@RequestBody JSONObject req){
        try {
            return afterserviceimp.searchAfter(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    //    按条件查找
    @RequestMapping("/searchAfters")
    public List<afterservice> searchAfters(@RequestBody JSONObject req){
        try {
            return afterserviceimp.searchAfter(req);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

}
